from rest_framework import serializers
from .models import StudentScore


class StudentScoreSerializer(serializers.ModelSerializer):
    class Meta:
        model = StudentScore
        fields = '__all__'


class StudentScoreListSerializer(serializers.ModelSerializer):
    exam_date = serializers.SerializerMethodField()

    class Meta:
        model = StudentScore
        fields = ['id', 'student_id', 'student_name', 'subject', 'score',
                 'semester', 'exam_type', 'exam_date', 'remark']

    def get_exam_date(self, obj):
        return obj.exam_date.strftime('%Y-%m-%d') if obj.exam_date else None